import React, { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
//hooks路由守卫，配置白名单，白名单的页面即使没有登录也能访问
function useAuthRoute() {
    const nav = useNavigate()

    const { pathname } = useLocation()
    const token = localStorage.getItem('token')
    const whiteList = ['/index/order']

    useEffect(() => {
        if(!token&&!whiteList.includes(pathname)) {
            nav('/login')
        }
    }, [])
}

export default useAuthRoute